﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for QLVe
/// </summary>
public class QLVe
{
    public QLVe()
    { }

    public List<Ve> getAllKh()
    {
        List<Ve> list = new List<Ve>();
        ConnectionDB con = new ConnectionDB();
        string sql = "select * from Ve"; ;
        con.Cmd.CommandText = sql;
        SqlDataReader reader = con.Cmd.ExecuteReader();
        Ve ve = null;
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                ve = new Ve();
                ve.Mave = reader.GetString(0);
                ve.Ngaylap = reader.GetDateTime(1);
                ve.Machuyen = reader.GetInt32(2);
                ve.Makh = reader.GetString(3);               
                ve.Hinhthucthanhtoan = reader.GetString(4);
                ve.Trangthai = reader.GetString(5);
                list.Add(ve);
            }
        }
        return list;
    }

    public void datve(Ve ve)
    {
        ConnectionDB cn = new ConnectionDB();
        cn.Cmd.Parameters.Add(new SqlParameter("@1", ve.Ngaylap));
        cn.Cmd.Parameters.Add(new SqlParameter("@2", ve.Machuyen));
        cn.Cmd.Parameters.Add(new SqlParameter("@3", ve.Makh));
        cn.Cmd.Parameters.Add(new SqlParameter("@4", ve.Hinhthucthanhtoan));
        cn.Cmd.Parameters.Add(new SqlParameter("@5", ve.Trangthai));
        cn.Cmd.Parameters.Add(new SqlParameter("@6", ve.Nguoithanhtoan));
        cn.Cmd.CommandType = CommandType.StoredProcedure;
        cn.Cmd.CommandText = "datve";
        cn.Cmd.ExecuteNonQuery();
    }

    public List<Tinh> getAllTinh()
    {
        List<Tinh> list = new List<Tinh>();
        ConnectionDB cn = new ConnectionDB();
        cn.Cmd.CommandText = "select * from TinhThanh";
        SqlDataReader read = cn.Cmd.ExecuteReader();
        Tinh data = null;
        if (read.HasRows)
        {
            while (read.Read())
            {
                data = new Tinh();
                data.Matinh = read.GetString(0);
                data.Tentinh = read.GetString(1);
                list.Add(data);
            }
        }
        return list;
    }
}